/**
 * 初始化销售单据查询详情对话框
 */
var GoodsSaleListInfoDlg = {
    id: "GoodsSaleListTable",
    goodsSaleListInfoData: {}
};

/**
 * 清除数据
 */
GoodsSaleListInfoDlg.clearData = function () {
    this.goodsSaleListInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GoodsSaleListInfoDlg.set = function (key, val) {
    this.goodsSaleListInfoData[key] = (typeof val === "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
GoodsSaleListInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
GoodsSaleListInfoDlg.close = function () {
    parent.layer.close(window.parent.GoodsSaleList.layerIndex);
}

/**
 * 收集数据
 */
GoodsSaleListInfoDlg.collectData = function () {
    this
        .set('id')
        .set('goodsCode')
        .set('goodsModel')
        .set('goodsName')
        .set('goodsNum')
        .set('goodsUnit')
        .set('goodsPrice')
        .set('createBy')
        .set('createDate')
        .set('updateBy')
        .set('updateDate')
        .set('remarks')
        .set('delFlag')
        .set('goodsSaleId')
        .set('goodsId');
}


GoodsSaleListInfoDlg.initColumn = function () {
    return [
        {title: '主键', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '商品编码', field: 'goodsCode', visible: true, align: 'center', valign: 'middle'},
        {title: '商品型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '商品数量', field: 'goodsNum', visible: true, align: 'center', valign: 'middle'},
        {title: '商品单位', field: 'goodsUnit', visible: true, align: 'center', valign: 'middle'},
        {title: '销售价格', field: 'goodsPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'},
        {title: '销售ID', field: 'goodsSaleId', visible: false, align: 'center', valign: 'middle'},
        {title: '商品id', field: 'goodsId', visible: false, align: 'center', valign: 'middle'}
    ];
};

/**
 * 提交添加
 */
GoodsSaleListInfoDlg.addSubmit = function () {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/goodsSaleList/add", function (data) {
        Feng.success("添加成功!");
        window.parent.GoodsSaleList.table.refresh();
        GoodsSaleListInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.goodsSaleListInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
GoodsSaleListInfoDlg.editSubmit = function () {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/goodsSaleList/update", function (data) {
        Feng.success("修改成功!");
        window.parent.GoodsSaleList.table.refresh();
        GoodsSaleListInfoDlg.close();
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.goodsSaleListInfoData);
    ajax.start();
}

$(function () {
    var defaultColumns = GoodsSaleListInfoDlg.initColumn();
    var saleGoodsId = $("#saleGoodsId").val();
    var table = new BSTable(GoodsSaleListInfoDlg.id, "/goodsSaleList/detail/" + saleGoodsId, defaultColumns);
    table.setPaginationType("client");
    table.setTableHeight(0);
    table.setShowColumns(false);
    table.setShowRefresh(false);
    GoodsSaleListInfoDlg.table = table.init();
});
